<?php
namespace app\admin\controller;
use think\Validate;	
use think\Session;	
class Login extends \think\Controller
{
	 public function login()
	{
	  return view('login');
	}

	public function checklogin()
	{
	  $admin_account  = input('post.admin_account');
	  $admin_pwd      = input('post.admin_pwd');
	  $captcha      = input('post.captcha');	
	  if(empty($admin_account))
	  {
	  	$this->error("账号不可为空");
	  }
	  if(empty($admin_pwd))
	  {
	  	$this->error("密码不可为空");
	  }	
	  if(!captcha_check($captcha))
	  {
		$this->error("验证码错误");
	  };

	  $admin_pwd = md5($admin_pwd);
	  $ret = db('admin')->where("admin_account='{$admin_account}' and admin_pwd='{$admin_pwd}'")->find();
	  if($ret == false)
	  {
	  	$this->error("登陆失败");
	  }
		  else
		  {
		  	 session('admin_info', $ret);
		  	 session('admin_id', $ret['admin_id']);
		  	 $this->success("管理员登录成功","/admin/food/food_list");  //记得加上登陆成功后跳转的页面
		  }
	}

	public function logout() 
	{
        Session::clear();
        $this->redirect('admin/login/login');
	}
	
	public function cleaning() 
	{
		Session::clear();
		return [
			'msg'  => '成功清空缓存',
			'statu'=> 1
		];
    }
	
}
